package com.ll.wechat.friends.adapter;

import java.util.List;

import org.jivesoftware.smackx.search.ReportedData.Row;

import com.ll.wechat.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 联系人搜索结果列表适配器
 * 
 * @ClassName: AddFriendsAdapter
 * @author yeliangliang
 * @date 2015-8-25 下午9:59:01
 */
public class AddFriendsAdapter extends BaseAdapter {
	private Context mContext;
	private List<Row> mList;
	private LayoutInflater inflater;
	private HolderView holderView;
	public int selectPosition = -1 ;
	public AddFriendsAdapter(Context context, List<Row> list) {
		this.mContext = context;
		this.mList = list;
		inflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holderView = new HolderView();
			convertView = inflater.inflate(R.layout.item_add_friends_list, null);
			holderView.tView = (TextView) convertView.findViewById(R.id.tv_user_name);
			convertView.setTag(holderView);
		} else {
			holderView = (HolderView) convertView.getTag();
		}
		if (position == selectPosition) {
			convertView.setBackgroundColor(mContext.getResources().getColor(R.color.gray_item_bg_p));
		}else {
			convertView.setBackgroundColor(mContext.getResources().getColor(R.color.white));
		}
		holderView.tView.setText(mList.get(position).getValues("Username").get(0));
		return convertView;
	}

	private class HolderView {
		TextView tView;
	}
}
